﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.Utils;
namespace Ccit.OA.Question
{
    public partial class qst_statistics_otherview : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Query"] = "";
                _hidsRecId.Value = (Request.QueryString["xId"] != null) ? Request.QueryString["xId"].ToString() : "";
                _hidWJId.Value = (Request.QueryString["Id"] != null) ? Request.QueryString["Id"].ToString() : ""; 
            }
            InitPage();
        }

        private void InitPage()
        {
            QuestionBLL Bll = new QuestionBLL();
            if (_hidWJId.Value == "")
            {
                if (_hidsRecId.Value != "")
                {
                    ViewState["Query"] = " and $$qId$$ =" + _hidsRecId.Value + "";
                } 
                DataSet dSet = Bll.GetOptionsMessage(ViewState["Query"].ToString(), "0");
                if (dSet.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
                    {
                        DataRow dRow = dSet.Tables[0].Rows[i];
                        CreateTable(i, dRow);
                    }
                }
                
            }
            else
            { 
                DataSet dSetWJ = Bll.GetQuestion(_hidWJId.Value, "3");
                if (dSetWJ.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k < dSetWJ.Tables[0].Rows.Count; k++)
                    {
                        DataRow dRowWJ = dSetWJ.Tables[0].Rows[k];
                        HtmlTableRow oRow = new HtmlTableRow();  
                        HtmlTableCell oCellM = new HtmlTableCell();
                        oCellM.Align = "left";
                        oCellM.ColSpan = 2;
                        oCellM.Attributes["class"] = "row4";
                        oCellM.Attributes["width"] = "8%";
                        oCellM.InnerHtml = "<nobr>" + (k + 1).ToString() + "、" + dRowWJ["Qst_A2_30"].ToString() + "</nobr>";
                        oRow.Cells.Add(oCellM);
                        tbProduct.Rows.Add(oRow);
                        ViewState["Query"] = " and $$qId$$ =" + dRowWJ["Qst_A2_10"].ToString() + "";
                        DataSet dSet = Bll.GetOptionsMessage(ViewState["Query"].ToString(), "0");
                        for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
                        {
                            DataRow dRow = dSet.Tables[0].Rows[i];
                            CreateTable(i, dRow);
                        }
                    } 
                } 
            }
            Bll = null;
        }
        /// <summary>
        /// 生成table
        /// </summary>
        /// <param name="i"></param>
        /// <param name="dRow"></param>
        private void CreateTable(int i, DataRow dRow)
        {
            string Name="匿名";
            if(dRow["Qst_A1_80"].ToString()=="1")
                Name = SysInterface.GetNameStrByIdStr(dRow["Qst_A5_10"].ToString(),NameType.USER,"");
            int iLine = i;
            HtmlTableRow oRow = new HtmlTableRow();
            oRow.ID = "row_" + iLine.ToString();
            oRow.Attributes["class"] = "listrow2";
            if (_hidWJId.Value == "")
            {
                if (i == 0)
                {
                    HtmlTableCell oCellM = new HtmlTableCell();
                    oCellM.Align = "left";
                    oCellM.ColSpan = 2;
                    oCellM.Attributes["class"] = "row4";
                    oCellM.Attributes["width"] = "8%";
                    oCellM.InnerHtml = "<nobr>" + (i + 1).ToString() + "、" + dRow["Qst_A2_30"].ToString() + "</nobr>";
                    oRow.Cells.Add(oCellM);
                    tbProduct.Rows.Add(oRow);
                }
            }
            HtmlTableRow oRow1 = new HtmlTableRow(); 
            HtmlTableCell oCellX = new HtmlTableCell();
            oCellX.Align = "left";
            oCellX.Width = "14%";
            oCellX.InnerHtml = "员工姓名:"+Name;
            oRow1.Cells.Add(oCellX);
            HtmlTableCell oCellT = new HtmlTableCell();
            oCellT.Align = "center";
            oCellT.Width = "14%";
            oCellT.InnerHtml = "时间:" + dRow["Qst_A5_9995"].ToString();   
            oRow1.Cells.Add(oCellT);
            tbProduct.Rows.Add(oRow1);

            HtmlTableRow oRow2 = new HtmlTableRow(); 
            HtmlTableCell oCellY = new HtmlTableCell();
            oCellY.Align = "left";
            oCellY.Width = "14%";
            oCellY.InnerHtml = "意见:"+dRow["Qst_A5_40"].ToString();
            oRow2.Cells.Add(oCellY);
            tbProduct.Rows.Add(oRow2);

            HtmlTableRow oRow3 = new HtmlTableRow();
            HtmlTableCell oCellH = new HtmlTableCell();
            oCellH.ColSpan = 2;
            oCellH.Align = "center"; 
            oCellH.InnerHtml = "<hr align='left' width='98%'>";
            oRow3.Cells.Add(oCellH);
            tbProduct.Rows.Add(oRow3);
        }
    }
}
